package game.module.nn.logic;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import game.module.nn.bean.NnRound;

public class NnDataManager {

	private static Logger logger = LoggerFactory.getLogger(NnDataManager.class);

	static class SingletonHolder {
		static NnDataManager instance = new NnDataManager();
	}

	public static NnDataManager getInstance() {
		return SingletonHolder.instance;
	}

	private Cache<Integer, NnRound> roundCache = CacheBuilder.newBuilder().concurrencyLevel(8)
			.expireAfterAccess(2, TimeUnit.HOURS).build();

	public void addRoundCache(int playerId, NnRound ddzRound) {
		roundCache.put(playerId, ddzRound);
	}

	public NnRound getNnRoom(int playerId) {
		return roundCache.getIfPresent(playerId);
	}

	public void removePlayer(Integer aPlayerId) {
		roundCache.invalidate(aPlayerId);
	}
	
	public int getPlayerCount() {
		int countSum = (int) roundCache.size();
		return countSum;
	}

}
